package com.youbug.mall.product_pms.web;

import com.youbug.mall.product_pms.entity.PmsCategory;
import com.youbug.mall.product_pms.service.ICategoryService;
import com.youbug.mall.product_pms.vo.Catelog2Vo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;
@Controller
public class IndexController {

    @Autowired
    private ICategoryService categoryService;


    @GetMapping(value = {"/","index.html"})
    private String indexPage(Model model) {
        List<PmsCategory> categoryEntities = categoryService.getLevel1Categorys();
        model.addAttribute("categories",categoryEntities);

        return "index";
    }

    @GetMapping(value = "/index/catalog.json")
    @ResponseBody
    public Map<String, List<Catelog2Vo>> getCatalogJson() {

        Map<String, List<Catelog2Vo>> catalogJson = categoryService.getCatalogJson();

        return catalogJson;
    }
}
